package com.jcfk.eam.service.equ;

import com.jcfk.common.business.service.BaseService;
import com.jcfk.eam.dao.main.EquStatisticsPlanRepairOrderDao;
import com.jcfk.eam.domain.dto.main.EChartData;
import com.jcfk.eam.domain.dto.main.EChartDataItem;
import com.jcfk.eam.domain.dto.main.EquStatisticsDTO;
import com.jcfk.eam.domain.dto.main.EquStatisticsPlanRepairOrderDTO;
import com.jcfk.eam.domain.po.base.EamPlanRepairOrder;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EquStatisticsPlanRepairOrderService extends BaseService<EquStatisticsPlanRepairOrderDao, EamPlanRepairOrder> {

    /**
     * 计划检修数据统计
     */
    public EquStatisticsPlanRepairOrderDTO queryPlanRepairOrdeList(EquStatisticsDTO query) {
        EquStatisticsPlanRepairOrderDTO dto = new EquStatisticsPlanRepairOrderDTO();
        dto.setAectionStatistics(this.queryAectionStatistics(query));
        dto.setAnnualStatistics(this.queryAnnualStatistics(query));
        dto.setTeamStatistics(this.queryTeamStatistics(query));
        return dto;
    }

    /**
     * 计划检修-年度统计(折线)
     */
    private EChartData queryAnnualStatistics(EquStatisticsDTO query) {
        EChartData eChartData = new EChartData();
        List<EquStatisticsDTO> list = this.baseMapper.queryAnnualStatistics(query);
        if(list == null || list.isEmpty()){
            return eChartData;
        }

        list.forEach(item ->{
            eChartData.getXData().add(item.getXData());
            eChartData.getYData().add(item.getYData());
        });
        return eChartData;
    }

    /**
     * 计划检修-工段统计(柱状)
     */
    private EChartData queryAectionStatistics(EquStatisticsDTO query) {
        EChartData eChartData = new EChartData();
        List<EquStatisticsDTO> list = this.baseMapper.queryAectionStatistics(query);
        if(list == null || list.isEmpty()){
            return eChartData;
        }

        list.forEach(item ->{
            eChartData.getXData().add(item.getXData());
            eChartData.getYData().add(item.getYData());
        });
        return eChartData;
    }

    /**
     * 计划检修-班组统计(饼图)
     */
    private EChartData queryTeamStatistics(EquStatisticsDTO query) {
        EChartData eChartData = new EChartData();
        List<EChartDataItem> list = this.baseMapper.queryTeamStatistics(query);
        if(list == null || list.isEmpty()){
            return eChartData;
        }
        eChartData.setData(list);
        return eChartData;
    }
}
